package com.local.controller.index;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.local.model.LocalStation;
import com.local.page.LocalStationPage;
import com.local.service.face.LocalStationService;
import com.local.service.face.StreamingMediaService;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;

@RestController
@RequestMapping(value = "/index/station", method = RequestMethod.POST)
public class LocalIndexStationController extends BaseController
{
	@Autowired
	private LocalStationService localStationService;
	
	@Autowired
	private StreamingMediaService streamMediaService;
	
	@RequestMapping(value = "/stationAll.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap stationAll(@RequestBody LocalStationPage<LocalStation> pageInfo)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localStationService.findAllLocalStationByQueryForm(pageInfo);
			resultMap.put(CommonContans.STRUTS_DATA, pageInfo);
			resultMap.put("curTime", System.currentTimeMillis());
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/viewStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap viewStation(@RequestBody LocalStation localStation)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localStation = localStationService.findUniqueStation(localStation
					.getStationUuid());
			resultMap.put(CommonContans.STRUTS_DATA, localStation);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述： 修改
	 * 
	 * @Title: modifyLocalStation
	 * @param @param localStation
	 * @param @return
	 * @return ModelMap
	 * @user lyf 2015年7月16日
	 * @throws
	 */
	@RequestMapping(value = "/modifyLocalStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap modifyLocalStation(@RequestBody LocalStation localStation)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localStationService.modifyLocalStation(localStation);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述： 建立连接
	 * 
	 * @Title: connection
	 * @param @param localStation
	 * @param @return
	 * @return ModelMap
	 * @user Administrator 2015年7月16日
	 * @throws
	 */
	@RequestMapping(value = "/connection.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap connection(@RequestBody LocalStation localStation)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			streamMediaService.createConnect(localStation.getVidoUuid(), localStation.getEquipmentViewStream(), localStation.getResolution(), localStation.getViewUrl()+"/"+localStation.getStream(), false);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
}
